package cus1156.lab6;

import java.util.ArrayList;

/**
 * Represents a list of cats
 * @author Bonnie MacKellar
 *
 */
public class CatList {
	private ArrayList<Cat> cats = new ArrayList<Cat>();
	
	/**
	 * add one cat to the list, at the last position
	 * @param cat - a Cat to be added
	 */
	public void addCat(Cat cat)
	{
		cats.add(cat);
	}
	
	/**
	 * return the number of cats in the list
	 * @return number of cats in the list
	 */
	

	public int howManyCats()
	{
		return cats.size();
	}

	/**
	 * return the cat at the ith position
	 * @param pos - the position whose Cat we want to return
	 */
	public Cat getCatAtPos(int pos)
	{
	   return cats.get(pos);
	}
	
	
	/** search a cat by name
	 * JT
	 * @param nm
	 * @return
	 */
	
	public Cat GetCatByName(String nm)
	{
		for (int i=0; i<cats.size();i++)
		{
			if (cats.get(i).getName().equals(nm))
			{
				return cats.get(i);
				
			}
			
		}
		return null;
			
	}
	
	
	/**
	 * Pat Steel
	 * Method counts the number of cats in the ArrayList with a certain
	 * color, and then returns that number.
	 * @param color
	 * @return
	 */
	public int getNumColorCat(String color){
		int count = 0;
		String catColor;
		for(Cat kitty : cats){
			catColor = kitty.getColor();
			if(catColor.equals(color)){
				count++;
			}
		}
		return count;
	}
}
